﻿using DevExpress.XtraGrid.Demos.util;
using DevExpress.XtraSplashScreen;
using DXApplicationTangche.DTO;
using DXApplicationTangche.UC.成品出库单.service;
using mendian;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static DXApplicationTangche.UC.纳客.Form新建报表;

namespace DXApplicationTangche.UC.盘点.Service
{
    public class 盘点Service
    {
        /// <summary>
        /// 在盘点大计划下新增店铺盘点计划（如果已有店铺或者是错误计划号时返回空）
        /// </summary>
        /// <param name="stockInventoryPlanCode"></param>
        /// <param name="storeId"></param>
        /// <param name="storeName"></param>
        /// <param name="mnemonic"></param>
        /// <param name="remarks"></param>
        /// <returns></returns>
        public static StockInventoryPlanDTO saveAddStoreInventoryPlan(
            String stockInventoryPlanCode,
            String storeId,
            String storeName,
            String mnemonic,
            String remarks)
        {
            return FunctionHelper.JsonDeserialization<StockInventoryPlanDTO>(
                RestCall.httpGetMethod(
                    URL.接口url + "/stock/saveAddStoreInventoryPlan?stockInventoryPlanCode=" + stockInventoryPlanCode +
                    "&storeId=" + storeId +
                    "&storeName=" + storeName +
                    "&mnemonic=" + mnemonic +
                    "&remarks=" + remarks
                    )
                );
        }
        /// <summary>
        /// 取得全部库存盘点计划一览
        /// </summary>
        /// <returns></returns>
        public static List<StockInventoryPlanDTO> getStockInventoryPlanDTOALL()
        {
            return
                FunctionHelper.JsonDeserialization<List<StockInventoryPlanDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventoryPlanDTOALL"
                        )
                    );
        }
        /// <summary>
        /// 根据编号取得盘点计划信息
        /// </summary>
        /// <param name="stockInventoryPlanCode"></param>
        /// <returns></returns>
        /// 返回的是一个DTO, 所以不用List
        public static StockInventoryPlanDTO getStockInventoryPlanDTOByCode(String stockInventoryPlanCode)
        {
            return
                FunctionHelper.JsonDeserialization<StockInventoryPlanDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventoryPlanDTOByCode?stockInventoryPlanCode=" + stockInventoryPlanCode
                        )
                    );
        }
        /// <summary>
        /// 根据编号取得门店盘点计划信息（失败时返回空）
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <returns></returns>
        public static StockStoreInventoryPlanDTO getStockStoreInventoryPlanByCode(String stockStoreInventoryPlanCode)
        {
            return FunctionHelper.JsonDeserialization<StockStoreInventoryPlanDTO>(
                RestCall.httpGetMethod(
                    URL.接口url + "/stock/getStockStoreInventoryPlanByCode?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode
                    )
                );
        }
        /// <summary>
        /// 库存盘点计划完成
        /// </summary>
        /// <param name="stockInventoryPlanCode"></param>
        /// <returns></returns>
        public static StockInventoryPlanDTO saveStockInventoryPlanDone(String stockInventoryPlanCode)
        {
            return
                FunctionHelper.JsonDeserialization<StockInventoryPlanDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/saveStockInventoryPlanDone?stockInventoryPlanCode=" + stockInventoryPlanCode
                        )
                    );
        }
        /// <summary>
        /// 门店盘点计划完成
        /// </summary>
        /// <param name="stockInventoryPlanCode"></param>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <returns></returns>
        public static StockStoreInventoryPlanDTO saveStockStoreInventoryPlanDone(String stockInventoryPlanCode, String stockStoreInventoryPlanCode)
        {
            return
                FunctionHelper.JsonDeserialization<StockStoreInventoryPlanDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/saveStockStoreInventoryPlanDone?stockInventoryPlanCode=" + stockInventoryPlanCode +
                        "&stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode
                        )
                    );
        }
        /// <summary>
        /// 盘点计划下新增货物
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static StockInOutDetailDTO saveStockInventoryDetail(String stockStoreInventoryPlanCode, String barcode)
        {
            return
                FunctionHelper.JsonDeserialization<StockInOutDetailDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/saveStockInventoryDetail?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode
                        + "&barcode=" + barcode
                        )
                    );
        }
        /// <summary>
        /// 新建库存盘点计划
        /// </summary>
        /// <param name="stockInventoryPlanStartDate"></param>
        /// <param name="stockInventoryPlanEndDate"></param>
        /// <param name="shopId"></param>
        /// <param name="shopName"></param>
        /// <param name="mnemonic"></param>
        /// <param name="remarks"></param>
        /// <returns></returns>
        public static StockInventoryPlanDTO saveStockInventoryPlan(
            DateTime stockInventoryPlanStartDate,
            DateTime stockInventoryPlanEndDate,
            String mnemonic,
            String remarks)
        {
            return
                FunctionHelper.JsonDeserialization<StockInventoryPlanDTO>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/saveStockInventoryPlan?stockInventoryPlanStartDate=" + stockInventoryPlanStartDate
                        + "&stockInventoryPlanEndDate=" + stockInventoryPlanEndDate
                        + "&mnemonic=" + mnemonic
                        + "&remarks=" + remarks
                        )
                    );
        }
        /// <summary>
        /// 取得在库一览
        /// </summary>
        /// <returns></returns>
        public static List<ViewStockInDetailDTO> getViewStockInDetailAll()
        {
            return
                FunctionHelper.JsonDeserialization<List<ViewStockInDetailDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getViewStockInDetailAll"
                        )
                    );
        }
        /// <summary>
        /// 取得盘点已处理预览
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="surplusOrLose"></param>
        /// <returns></returns>
        public static List<StockInventoryPlanResultDTO> getStockInventoryAllTreated(String stockStoreInventoryPlanCode, String surplusOrLose)
        {
            return
                FunctionHelper.JsonDeserialization<List<StockInventoryPlanResultDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventoryAllTreated?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode +
                        "&surplusOrLose=" + surplusOrLose
                        )
                    );
        }
        /// <summary>
        /// 取得盘盈一览
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <returns></returns>
        public static List<StockStoreInventoryResultDTO> getStockInventorySurplusAll(String stockStoreInventoryPlanCode)
        {
            return
                FunctionHelper.JsonDeserialization<List<StockStoreInventoryResultDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventorySurplusAll?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode
                        )
                    );
        }
        /// <summary>
        /// 取得盘亏一览
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <returns></returns>
        public static List<StockStoreInventoryResultDTO> getStockInventoryLoseAll(String stockStoreInventoryPlanCode)
        {
            return
                FunctionHelper.JsonDeserialization<List<StockStoreInventoryResultDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventoryLoseAll?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode
                        )
                    );
        }
        /// <summary>
        /// 盘点结果处理
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="inOutFlag"></param>
        /// <param name="inOutType"></param>
        /// <param name="InStoreId"></param>
        /// <param name="InStoreName"></param>
        /// <param name="outStoreId"></param>
        /// <param name="outStoreName"></param>
        /// <param name="mnemonic"></param>
        /// <param name="remarks"></param>
        /// <param name="stockInOutDetailDTOS"></param>
        /// <returns></returns>
        public static StockInOutTitleDTO saveStockInventoryResult(
            String stockStoreInventoryPlanCode,
            String inOutFlag,
            String inOutType,
            String InStoreId,
            String InStoreName,
            String outStoreId,
            String outStoreName,
            String mnemonic,
            String remarks,
            List<StockInOutDetailDTO> stockInOutDetailDTOS
            )
        {
            return
                FunctionHelper.JsonDeserialization<StockInOutTitleDTO>(
                    RestCall.PostHttp(
                        URL.接口url + "/stock/saveStockInventoryResult?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode +
                        "&inOutFlag=" + inOutFlag +
                        "&inOutType=" + inOutType +
                        "&InStoreId=" + InStoreId +
                        "&InStoreName=" + InStoreName +
                        "&outStoreId=" + outStoreId +
                        "&outStoreName=" + outStoreName +
                        "&mnemonic=" + mnemonic +
                        "&remarks=" + remarks,
                        FunctionHelper.JsonSerialization(stockInOutDetailDTOS)
                        )
                    );
        }
        /// <summary>
        /// 将多个盘点货物完成
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="mnemonic"></param>
        /// <param name="remarks"></param>
        /// <param name="stockInOutTitleId"></param>
        /// <param name="surplusOrLose"></param>
        /// <param name="stockInOutDetailDTOS"></param>
        /// <returns></returns>
        public static Boolean saveStockInventoryResultDone(
            String stockStoreInventoryPlanCode,
            String mnemonic,
            String remarks,
            String stockInOutTitleId,
            String surplusOrLose,//盘盈或盘亏（0盘亏，1盘盈）
            List<StockInOutDetailDTO> stockInOutDetailDTOS
            )
        {
            return
                FunctionHelper.JsonDeserialization<Boolean>(
                    RestCall.PostHttp(
                        URL.接口url + "/stock/saveStockInventoryResultDone?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode +
                        "&mnemonic=" + mnemonic +
                        "&remarks=" + remarks +
                        "&stockInOutTitleId=" + stockInOutTitleId +
                        "&surplusOrLose=" + surplusOrLose,
                        FunctionHelper.JsonSerialization(stockInOutDetailDTOS)
                        )
                    );
        }
        /// <summary>
        /// 将盘盈入库一览做盘盈入库
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="mnemonic"></param>
        /// <param name="remarks"></param>
        /// <param name="stockInOutDetailDTOS"></param>
        /// <returns></returns>
        public static StockInOutTitleDTO saveStockInventorySurplusIn(
            String stockStoreInventoryPlanCode,
            String mnemonic,
            String remarks,
            List<StockInOutDetailDTO> stockInOutDetailDTOS
            )
        {
            return
                FunctionHelper.JsonDeserialization<StockInOutTitleDTO>(
                    RestCall.PostHttp(
                        URL.接口url + "/stock/saveStockInventorySurplusIn?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode +
                        "&mnemonic=" + mnemonic +
                        "&remarks=" + remarks,
                        FunctionHelper.JsonSerialization(stockInOutDetailDTOS)
                        )
                    );
        }
        /// <summary>
        /// 扫货号取得相同款式面料的款式在库一览
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static List<ViewStockInDetailDTO> getViewStockInDetailByBarcode(String barcode)
        {
            return FunctionHelper.JsonDeserialization<List<ViewStockInDetailDTO>>(
                RestCall.httpGetMethod(
                    URL.接口url + "/stock/getViewStockInDetailByBarcode?barcode=" + barcode
                    )
                );
        }
        /// <summary>
        /// 取得盘点全部结果一览
        /// </summary>
        /// <param name="stockStoreInventoryPlanCode"></param>
        /// <param name="surplusOrLose"></param>
        /// <returns></returns>
        public static List<StockInventoryPlanResultDTO> getStockInventoryAll(String stockStoreInventoryPlanCode, String surplusOrLose)
        {
            return
                FunctionHelper.JsonDeserialization<List<StockInventoryPlanResultDTO>>(
                    RestCall.httpGetMethod(
                        URL.接口url + "/stock/getStockInventoryAll?stockStoreInventoryPlanCode=" + stockStoreInventoryPlanCode +
                        "&surplusOrLose=" + surplusOrLose
                        )
                    );
        }

        public static Dictionary<String, ViewStockSpecDTO> viewStockSpecDTOs()
        {
            return
                FunctionHelper.JsonDeserialization<Dictionary<String, ViewStockSpecDTO>>(
                    RestCall.httpGetMethod(
                       URL.接口url + "/stock/getViewStockSpecBySpecNo"
                    )
                );
        }
        public static void saveExcelFor盘点完成(SplashScreenManager splashScreenManager, StockStoreInventoryPlanDTO stockStoreInventoryPlanDTO, List<StockInventoryPlanResultDTO> stock所有盘盈, List<StockInventoryPlanResultDTO> stock所有盘亏)
        {
            System.Windows.Forms.FolderBrowserDialog sFD = new System.Windows.Forms.FolderBrowserDialog();
            System.Windows.Forms.DialogResult rdr = sFD.ShowDialog();
            string filePath = sFD.SelectedPath;
            splashScreenManager.ShowWaitForm();
            splashScreenManager.SetWaitFormCaption("请稍后,正在保存中....");     // 标题
            splashScreenManager.SetWaitFormDescription("正在初始化.....");     // 信息
            List<StockStoreInventoryResultOverview> stockStoreInventoryResultOverviews = 盘点Service.getStockStoreInventoryResultOverviews(stockStoreInventoryPlanDTO);
            XSSFWorkbook workbook = new XSSFWorkbook();
            ISheet sheet = null;
            ISheet sheet1 = null;
            ISheet sheet2 = null;
            ISheet sheet3 = null;
            DateTime now = DateTime.Now;
            filePath = filePath + "\\" + now.ToString("yyyy年MM月dd日HH时mm分") + "盘点完成结果.xlsx";
            FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            int i = 0;
            try
            {
                #region 盘点完成总览
                sheet = workbook.CreateSheet(now.ToString("yyyy年MM月dd日") + "盘点完成总览");
                IRow rowTitle = sheet.CreateRow(0);
                rowTitle.CreateCell(0).SetCellValue("款式名称");
                rowTitle.CreateCell(1).SetCellValue("面料号");
                rowTitle.CreateCell(2).SetCellValue("面料名称");
                rowTitle.CreateCell(3).SetCellValue("尺寸");
                rowTitle.CreateCell(4).SetCellValue("账面数");
                rowTitle.CreateCell(5).SetCellValue("实际盘点数");
                rowTitle.CreateCell(6).SetCellValue("盘盈数");
                rowTitle.CreateCell(7).SetCellValue("盘亏数");
                for (i = 0; i < stockStoreInventoryResultOverviews.Count; i++)
                {
                    IRow rowTitlei = sheet.CreateRow(i + 1);
                    rowTitlei.CreateCell(0).SetCellValue(stockStoreInventoryResultOverviews[i].styleNameCn);
                    rowTitlei.CreateCell(1).SetCellValue(stockStoreInventoryResultOverviews[i].fabricCode);
                    rowTitlei.CreateCell(2).SetCellValue(stockStoreInventoryResultOverviews[i].fabricName);
                    rowTitlei.CreateCell(3).SetCellValue(stockStoreInventoryResultOverviews[i].styleSizeCd);
                    rowTitlei.CreateCell(4).SetCellValue(stockStoreInventoryResultOverviews[i].BookAmount);
                    rowTitlei.CreateCell(5).SetCellValue(stockStoreInventoryResultOverviews[i].ActualNumber);
                    rowTitlei.CreateCell(6).SetCellValue(stockStoreInventoryResultOverviews[i].SurplusNumber);
                    rowTitlei.CreateCell(7).SetCellValue(stockStoreInventoryResultOverviews[i].LoseNumber);
                }
                #endregion
                #region 盘亏概况一览
                //sheet1 = workbook.CreateSheet(now.ToString("yyyy年MM月dd日") + "盘亏概况一览");
                //IRow rowTitle1 = sheet1.CreateRow(0);
                //rowTitle1.CreateCell(0).SetCellValue("款式名称");
                //rowTitle1.CreateCell(1).SetCellValue("尺寸");
                //rowTitle1.CreateCell(2).SetCellValue("面料号");
                //rowTitle1.CreateCell(3).SetCellValue("面料名称");
                //rowTitle1.CreateCell(4).SetCellValue("总数");
                //rowTitle1.CreateCell(5).SetCellValue("差数");
                //for (i = 0; i < stockStoreInventoryPlanDTO.stockLoseResultDTOS.Count; i++)
                //{
                //    IRow rowTitlei = sheet1.CreateRow(i + 1);
                //    rowTitlei.CreateCell(0).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].styleNameCn);
                //    rowTitlei.CreateCell(1).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].styleSizeCd);
                //    rowTitlei.CreateCell(2).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].fabricCode);
                //    rowTitlei.CreateCell(3).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].fabricName);
                //    rowTitlei.CreateCell(4).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].totalInventory);
                //    rowTitlei.CreateCell(5).SetCellValue(stockStoreInventoryPlanDTO.stockLoseResultDTOS[i].differenceNumber);
                //}
                #endregion
                #region 盘盈处理结果
                sheet2 = workbook.CreateSheet(now.ToString("yyyy年MM月dd日") + "盘盈处理结果");
                IRow rowTitle2 = sheet2.CreateRow(0);
                rowTitle2.CreateCell(0).SetCellValue("门店名称");
                rowTitle2.CreateCell(1).SetCellValue("货号");
                rowTitle2.CreateCell(2).SetCellValue("款式名称");
                rowTitle2.CreateCell(3).SetCellValue("尺码");
                rowTitle2.CreateCell(4).SetCellValue("面料号");
                rowTitle2.CreateCell(5).SetCellValue("面料名称");
                rowTitle2.CreateCell(6).SetCellValue("价格");
                rowTitle2.CreateCell(7).SetCellValue("是否处理");
                rowTitle2.CreateCell(8).SetCellValue("处理结果");
                rowTitle2.CreateCell(9).SetCellValue("处理人");
                for (i = 0; i < stock所有盘盈.Count; i++)
                {
                    IRow rowTitlei = sheet2.CreateRow(i + 1);
                    rowTitlei.CreateCell(0).SetCellValue(stock所有盘盈[i].storeName);
                    rowTitlei.CreateCell(1).SetCellValue(stock所有盘盈[i].barcode);
                    rowTitlei.CreateCell(2).SetCellValue(stock所有盘盈[i].styleNameCn);
                    rowTitlei.CreateCell(3).SetCellValue(stock所有盘盈[i].styleSizeCd);
                    rowTitlei.CreateCell(4).SetCellValue(stock所有盘盈[i].fabricCode);
                    rowTitlei.CreateCell(5).SetCellValue(stock所有盘盈[i].fabricName);
                    rowTitlei.CreateCell(6).SetCellValue(stock所有盘盈[i].price);
                    rowTitlei.CreateCell(7).SetCellValue(stock所有盘盈[i].hasTreated);
                    rowTitlei.CreateCell(8).SetCellValue(stock所有盘盈[i].remarks);
                    rowTitlei.CreateCell(9).SetCellValue(stock所有盘盈[i].name);
                }
                #endregion
                #region 盘亏处理结果
                sheet3 = workbook.CreateSheet(now.ToString("yyyy年MM月dd日") + "盘亏处理结果");
                IRow rowTitle3 = sheet3.CreateRow(0);
                rowTitle3.CreateCell(0).SetCellValue("门店名称");
                rowTitle3.CreateCell(1).SetCellValue("货号");
                rowTitle3.CreateCell(2).SetCellValue("款式名称");
                rowTitle3.CreateCell(3).SetCellValue("尺码");
                rowTitle3.CreateCell(4).SetCellValue("面料号");
                rowTitle3.CreateCell(5).SetCellValue("面料名称");
                rowTitle3.CreateCell(6).SetCellValue("价格");
                rowTitle3.CreateCell(7).SetCellValue("是否处理");
                rowTitle3.CreateCell(8).SetCellValue("处理结果");
                rowTitle3.CreateCell(9).SetCellValue("处理人");
                for (i = 0; i < stock所有盘亏.Count; i++)
                {
                    IRow rowTitlei = sheet3.CreateRow(i + 1);
                    rowTitlei.CreateCell(0).SetCellValue(stock所有盘亏[i].storeName);
                    rowTitlei.CreateCell(1).SetCellValue(stock所有盘亏[i].barcode);
                    rowTitlei.CreateCell(2).SetCellValue(stock所有盘亏[i].styleNameCn);
                    rowTitlei.CreateCell(3).SetCellValue(stock所有盘亏[i].styleSizeCd);
                    rowTitlei.CreateCell(4).SetCellValue(stock所有盘亏[i].fabricCode);
                    rowTitlei.CreateCell(5).SetCellValue(stock所有盘亏[i].fabricName);
                    rowTitlei.CreateCell(6).SetCellValue(stock所有盘亏[i].price);
                    rowTitlei.CreateCell(7).SetCellValue(stock所有盘亏[i].hasTreated);
                    rowTitlei.CreateCell(8).SetCellValue(stock所有盘亏[i].remarks);
                    rowTitlei.CreateCell(9).SetCellValue(stock所有盘亏[i].name);
                }
                #endregion
                workbook.Write(fileStream); //写入到excel
                workbook.Close();
            }
            catch (Exception ex)
            {

            }
        }

        public static List<StockStoreInventoryResultOverview> getStockStoreInventoryResultOverviews(StockStoreInventoryPlanDTO stockStoreInventoryPlanDTO)
        {
            List<StockStoreInventoryResultOverview> stockStoreInventoryResultOverviews = new List<StockStoreInventoryResultOverview>();
            List<String> names = new List<String>();
            //做盘盈
            foreach (StockStoreInventoryResultDTO dTO in stockStoreInventoryPlanDTO.stockSurplusResultDTOS)
            {
                StockStoreInventoryResultOverview xxx = new StockStoreInventoryResultOverview(dTO);
                stockStoreInventoryResultOverviews.Add(xxx);
                names.Add(xxx.name);
            }
            if (stockStoreInventoryResultOverviews == null || stockStoreInventoryResultOverviews.Count == 0)
            {//没有盘盈时（只做盘亏）
                foreach (StockStoreInventoryResultDTO dTO1 in stockStoreInventoryPlanDTO.stockLoseResultDTOS)
                {
                    stockStoreInventoryResultOverviews.Add(new StockStoreInventoryResultOverview(dTO1,""));
                }
            }
            else
            {//有盘盈时
                foreach (StockStoreInventoryResultDTO dTO1 in stockStoreInventoryPlanDTO.stockLoseResultDTOS)
                {
                    String name = dTO1.buildNames();
                    if (names.Contains(name))
                    {//有盘盈有盘亏时
                        for (int i = stockStoreInventoryResultOverviews.Count - 1; i >= 0; i--)
                        {
                            if (name.Equals(stockStoreInventoryResultOverviews[i].name))
                            {
                                stockStoreInventoryResultOverviews[i].buildLose(dTO1);
                                break;
                            }
                        }
                    }
                    else
                    {//只有盘亏时
                        stockStoreInventoryResultOverviews.Add(new StockStoreInventoryResultOverview(dTO1,""));
                    }
                }
            }
            return stockStoreInventoryResultOverviews;
        }
    }
    /// <summary>
    /// 库存盘点大计划
    /// </summary>
    public class StockInventoryPlanDTO
    {
        public String stockInventoryPlanCode { get; set; }//盘点计划号
        public DateTime stockInventoryPlanStartDate { get; set; }//开始时间
        public DateTime stockInventoryPlanEndDate { get; set; }//结束时间
        public String mnemonic { get; set; }//操作人工号
        public String name { get; set; }//操作人名称
        public String remarks { get; set; }//备注
        public Boolean isDone { get; set; }//是否完成
        public List<StockStoreInventoryPlanShowDTO> stockStoreInventoryPlanShowDTOS { get; set; } = new List<StockStoreInventoryPlanShowDTO>();//门店盘点计划
        public StockInventoryPlanDTO()
        {

        }
        public StockInventoryPlanDTO(
            DateTime stockInventoryPlanStartDate,
            DateTime stockInventoryPlanEndDate,
            String mnemonic,
            String remarks
            )
        {
            this.stockInventoryPlanStartDate = stockInventoryPlanStartDate;
            this.stockInventoryPlanEndDate = stockInventoryPlanEndDate;
            this.mnemonic = mnemonic;
            this.remarks = remarks;
        }
    }
    /// <summary>
    /// 门店盘点计划下展示（刨除盘点货物明细）
    /// </summary>
    public class StockStoreInventoryPlanShowDTO
    {
        public String stockStoreInventoryPlanCode { get; set; }//门店盘点计划号
        public String storeId { get; set; }//店铺id
        public String storeName { get; set; }//店铺名称
        public String mnemonic { get; set; }//操作人工号
        public String name { get; set; }//操作人名称
        public String remarks { get; set; }//备注
        public Boolean isDone { get; set; }//是否完成
    }
    /// <summary>
    /// 门店盘点计划
    /// </summary>
    public class StockStoreInventoryPlanDTO
    {
        public String stockStoreInventoryPlanCode { get; set; }//门店盘点计划号
        public String storeId { get; set; }//店铺id
        public String storeName { get; set; }//店铺名称
        public String mnemonic { get; set; }//操作人工号
        public String name { get; set; }//操作人名称
        public String remarks { get; set; }//备注
        public Boolean isDone { get; set; }//是否完成
        public List<StockInOutDetailDTO> stockInOutDetailDTOS { get; set; } = new List<StockInOutDetailDTO>();//盘点货物
        public List<StockStoreInventoryResultDTO> stockSurplusResultDTOS { get; set; } = new List<StockStoreInventoryResultDTO>();//盘盈结果
        public List<StockStoreInventoryResultDTO> stockLoseResultDTOS { get; set; } = new List<StockStoreInventoryResultDTO>();//盘亏结果
    }
    /// <summary>
    /// 在库一览明细
    /// </summary>
    public class ViewStockInDetailDTO
    {
        public String id { get; set; }
        public String titleId { get; set; }//表头id
        public String inOutCode { get; set; }
        public String barcode { get; set; }
        public String batchNo { get; set; }//批号

        public String styleNameCn { get; set; }//  款式名称
        public String styleSizeCd { get; set; }//尺码

        public String fabricId { get; set; }//面料id
        public String fabricCode { get; set; }//面料编码
        public String fabricName { get; set; }//面料名称
        public String fabricComposition { get; set; }//面料成分

        public DateTime inOutDate { get; set; }
        public int inOutFlag { get; set; }
        public String inOutType { get; set; }
        public String outStoreId { get; set; }
        public String outStoreName { get; set; }
        public String inStoreId { get; set; }
        public String inStoreName { get; set; }

        public String refStyleId { get; set; }
        public String inventory { get; set; }
        public double price { get; set; }

        public String mnemonic { get; set; }
        public String name { get; set; }
        public String remarks { get; set; }
        public ViewStockInDetailDTO()
        {

        }
    }
    /// <summary>
    /// 盘点完成后的结果
    /// </summary>
    public class StockInventoryPlanResultDTO
    {
        public String id { get; set; }
        public String stockInventoryPlanCode { get; set; }//盘点大计划编号
        public String stockStoreInventoryPlanCode { get; set; }//门店盘点计划编号
        public String storeId { get; set; }//门店id
        public String storeName { get; set; }//门店名称
        public String barcode { get; set; }//货号
        public String styleNameCn { get; set; }//款式名称
        public String styleSizeCd { get; set; }//尺码
        public String fabricId { get; set; }//面料id
        public String fabricCode { get; set; }//面料号
        public String fabricName { get; set; }//面料名称
        public String fabricComposition { get; set; }//面料成分
        public double price { get; set; }//价格
        public String surplusOrLose { get; set; }//盘盈或盘亏
        public String hasTreated { get; set; }//是否处理
        public String remarks { get; set; }//处理结果
        public String mnemonic { get; set; }//处理人号
        public String name { get; set; }//处理人
        public String stockInOutTitleId { get; set; }//出入库抬头id

        public StockInventoryPlanResultDTO()
        {

        }
    }
    /// <summary>
    /// 盘点未完成一览
    /// </summary>
    public class StockStoreInventoryResultDTO
    {
        public String styleNameCn { get; set; }//款式名称
        public String styleSizeCd { get; set; }//尺寸
        public String fabricCode { get; set; }//面料号
        public String fabricName { get; set; }//面料名称
        public int totalInventory { get; set; }//总数
        public int differenceNumber { get; set; }//差数
        public List<StockInOutDetailDTO> stockInOutDetailDTOS { get; set; } = new List<StockInOutDetailDTO>();

        public StockStoreInventoryResultDTO()
        {

        }

        public String buildNames()
        {
            return this.styleNameCn + this.styleSizeCd + this.fabricCode;
        }
    }
    /// <summary>
    /// 门店盘点计划展示
    /// </summary>
    public class StockInOutDetailDTOShow
    {
        public Boolean choose { get; set; }//选择
        public String barcode { get; set; } //成衣码
        public String batchNo { get; set; } ////批号
        public String styleNameCn { get; set; } // //  款式名称
        public String styleSizeCd { get; set; } ////尺码
        public String fabricId { get; set; } //
        public String fabricCode { get; set; } //面料号
        public String fabricName { get; set; } //面料名称
        public String fabricComposition { get; set; } //面料成分
        public DateTime salesTime { get; set; } //
        public int inOutFlag { get; set; } //出入库标识：0出库，1入库
        public String inOutType { get; set; } //出入库类型
        public String storeId { get; set; } //
        public String storeName { get; set; }
        //  货号信息
        public String refStyleId { get; set; } //
        public String inventory { get; set; } //
        public double price { get; set; } //
        public String mobile { get; set; } //
        public String customerName { get; set; }
        public StockInOutDetailDTOShow()
        {

        }
        public StockInOutDetailDTOShow(StockInOutDetailDTO stock, Boolean b)
        {
            this.choose = b;
            this.barcode = stock.barcode;//成衣码
            this.batchNo = stock.batchNo;////批号
            this.styleNameCn = stock.styleNameCn;// //  款式名称
            this.styleSizeCd = stock.styleSizeCd;////尺码
            this.fabricId = stock.fabricId;//
            this.fabricCode = stock.fabricCode;//面料号
            this.fabricName = stock.fabricName;//面料名称
            this.fabricComposition = stock.fabricComposition;//面料成分
            this.salesTime = stock.salesTime;//
            this.inOutFlag = stock.inOutFlag;//出入库标识：0出库，1入库
            this.inOutType = stock.inOutType;//出入库类型

            this.storeId = stock.storeId;//
            this.storeName = stock.storeName;
            //  货号信息
            this.refStyleId = stock.refStyleId;//
            this.inventory = stock.inventory;//
            this.price = stock.price;
            this.mobile = stock.mobile;//
            this.customerName = stock.customerName;
        }
    }
    /// <summary>
    /// 门店盘点计划总览
    /// </summary>
    public class StockStoreInventoryResultOverview
    {
        public String name { get; set; }
        public String styleNameCn { get; set; }
        public String fabricCode { get; set; }
        public String fabricName { get; set; }
        public String styleSizeCd { get; set; }
        public int BookAmount { get; set; }//账面数
        public int ActualNumber { get; set; }//实际盘点数
        public int SurplusNumber { get; set; }//盘盈数
        public int LoseNumber { get; set; }//盘亏数
        /// <summary>
        /// 盘盈用
        /// </summary>
        /// <param name="stock"></param>
        public StockStoreInventoryResultOverview(StockStoreInventoryResultDTO stock)
        {
            this.styleNameCn = stock.styleNameCn;
            this.fabricCode = stock.fabricCode;
            this.fabricName = stock.fabricName;
            this.styleSizeCd = stock.styleSizeCd;
            this.BookAmount = stock.totalInventory;
            this.ActualNumber = this.BookAmount + stock.differenceNumber;
            this.SurplusNumber = stock.differenceNumber;
            this.LoseNumber = 0;
            this.name = this.styleNameCn + this.styleSizeCd + this.fabricCode;
        }
        /// <summary>
        /// 有盘盈有盘亏
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        public StockStoreInventoryResultOverview buildLose(StockStoreInventoryResultDTO stock)
        {
            this.ActualNumber = this.ActualNumber - stock.differenceNumber;
            this.LoseNumber = stock.differenceNumber;
            return this;
        }
        /// <summary>
        /// 只有盘亏时
        /// </summary>
        /// <param name="stock"></param>
        /// <param name="盘亏"></param>
        public StockStoreInventoryResultOverview(StockStoreInventoryResultDTO stock,String 盘亏)
        {
            this.styleNameCn = stock.styleNameCn;
            this.fabricCode = stock.fabricCode;
            this.fabricName = stock.fabricName;
            this.styleSizeCd = stock.styleSizeCd;
            this.BookAmount = stock.totalInventory;
            this.ActualNumber = this.BookAmount - stock.differenceNumber;
            this.SurplusNumber = 0;
            this.LoseNumber = stock.differenceNumber;
            this.name = this.styleNameCn + this.fabricCode + this.styleSizeCd;
        }
    }
}
